package com.goldgov.overview.web;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.goldgov.overview.service.OverviewService;

@RestController
@RequestMapping("overview")
public class OverviewController {
	
	@Autowired
	private OverviewService overviewService;

	@GetMapping("/week")
	public Map<String, Map<String, Object>> listInfoItem(){
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.DAY_OF_WEEK,1);
		Date startDate = cal.getTime();
		cal.set(Calendar.DAY_OF_WEEK,7);
		Date endDate = cal.getTime();
		
		cal.add(Calendar.WEEK_OF_YEAR, -1);
//		cal.set(Calendar.DAY_OF_WEEK,1);
		Date lastEndDate = cal.getTime();
		cal.add(Calendar.DAY_OF_YEAR,-6);
		Date lastStartDate = cal.getTime();
		
		Map<String, Object> weekInfoItem = overviewService.listInfoItem(startDate, endDate);
		Map<String, Object> lastWeekInfoItem = overviewService.listInfoItem(lastStartDate, lastEndDate);
		weekInfoItem.put("START_DATE", startDate.getTime());
		weekInfoItem.put("END_DATE", endDate.getTime());
		
		Map<String, Map<String, Object>> valueMap = new HashMap<>();
		valueMap.put("thisWeekInfo", weekInfoItem);
		valueMap.put("lastWeekInfo", lastWeekInfoItem);
		return valueMap;
	}
	
	@GetMapping("/week/active")
	public Map<Long, Integer> listMonthActiveState(){
		Map<Long, Integer> listMonthActiveState = overviewService.listMonthActiveState();
		return listMonthActiveState;
	}
	
}
